#include "Renderer/ButtonRenderer.h"
#include "Scheme/GUIWidgetLookManager.h"

namespace YGUI
{
    const String ButtonRenderer::TypeName("Button");

    ButtonRenderer::ButtonRenderer(const String& type) : WindowRenderer(type)
    {
    }

    ButtonRenderer::~ButtonRenderer(void)
    {
    }

    void ButtonRenderer::render(void)
    {
        ButtonBase* wnd = (ButtonBase*)(m_window);
        
        assert(wnd);

        bool is_normal = false;

        String look_name;
        if(wnd->isDisabled())
            look_name = "Disaled";
        else if(wnd->isPushed())
            look_name = wnd->isHovering() ? "Pushed" : "PushedOff";
        else if(wnd->isHovering())
            look_name = "Hover";
        else { is_normal = true; look_name = "Normal"; }

        try
        {
            const WidgetLook& wl = getLook();
            if(!is_normal && !wl.isStateImageryExists(look_name))
                look_name = "Normal";
            const StateImagery& state_img = wl.getStateImagery(look_name);
            state_img.render(*m_window);
        }
        catch(...) 
        { }
    }
}